package com.example.a33mvvm.register;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.example.base_mvvm.base.BaseViewModel;
import com.example.base_mvvm.entity.RegisterEntity;
import com.example.base_mvvm.net.Const;
import com.google.gson.Gson;

import java.util.HashMap;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RegisterViewModel extends BaseViewModel<RegisterRepo> {
    public MutableLiveData<RegisterEntity> success = new MutableLiveData<>();
    public MutableLiveData<String> failure = new MutableLiveData<>();
    public RegisterViewModel(@NonNull Application application) {
        super(application);
    }
    public void register(String username,String password,String repassowrd){
        HashMap<String, String> map = new HashMap<>();
        map.put(Const.USERNAME,username);
        map.put(Const.PASSWORD,password);
        map.put(Const.RE_PASSWORD,repassowrd);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.PARSE),json);
        repo.register(body,success,failure);
    }

    @Override
    protected RegisterRepo createRepo() {
        return new RegisterRepo();
    }
}
